package cn.sc.allinpay.allfavour.business.common.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.AppCompatEditText;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.Toast;

import cn.sc.allinpay.allfavour.R;

/**
 * description：验券备注输入弹出框
 * author：pany
 * on 2018/7/28 17:36
 */
public class CheckInputRemarkDialog extends Dialog implements View.OnClickListener {

    private AppCompatEditText etRemark;
    private OnDialogListener onDialogListener;

    public CheckInputRemarkDialog(@NonNull Context context) {
        super(context);
    }

    public CheckInputRemarkDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog_check_input_remark);
        etRemark = findViewById(R.id.etRemark);
        findViewById(R.id.btnConfirm).setOnClickListener(this);
        findViewById(R.id.btnCancel).setOnClickListener(this);
    }

    public void setOnDialogListener(OnDialogListener onDialogListener) {
        this.onDialogListener = onDialogListener;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btnConfirm:
                String remark = etRemark.getText().toString().trim();
                if (TextUtils.isEmpty(remark)) {
                    Toast.makeText(getContext(), "备注信息不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                dismiss();
                if (onDialogListener != null) {
                    onDialogListener.onConfirm(etRemark.getText().toString().trim());
                }
                break;
            case R.id.btnCancel:
                dismiss();
                if (onDialogListener != null) {
                    onDialogListener.onCancel();
                }
                break;
        }
    }

    public static abstract class OnDialogListener {

        protected abstract void onConfirm(String input);

        protected void onCancel() {
        }
    }
}
